<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Bezdelnick
 * Date: 17.03.13
 * Time: 16:56
 * To change this template use File | Settings | File Templates.
 */
$PATH = Config::getInstance()->getBasePath();
require_once("$PATH/dao/AbstractDao.php");
require_once("$PATH/controller/ActorController.php");

class ActorDao extends AbstractDao
{
    function __construct()
    {
        $this->controller = new ActorController();
    }

    public function loadByFilmId($id)
    {
        $filmController = new FilmController();
        // Create query
        $query =
            "SELECT * FROM actors INNER JOIN (films, rel_film_actor)
            ON (films.id=rel_film_actor.film_id AND films.id=" + $id + ")";

        // Load data from database
        $result = mysql_query(
            $query, Config::getInstance()->getDbConnection()
        );

        // Build object's array
        $instances = array();
        while ($row = mysql_fetch_array($result)) {
            $instance = PatternUtil::getInstance()->getObjectFromArray(
                $this->controller, $row);
            array_push($instances, $instance);

            /*var_dump($instance);
            echo "<br/>";*/
        }
        return $instances;
    }
}
